package acm.pta9;

import java.util.*;

public class 地铁一日游 {
    public static void main(String[] args) {
        Reader sc = new Reader();
        int n = sc.nextInt();
        int m= sc.nextInt();
        int k = sc.nextInt();
        Graph graph = new Graph(n);
        while (m-- > 0) {
             graph.insert(sc.nextLine().split(" "));
        }
        graph.builder();
        m = sc.nextInt();
        while (m-- > 0) {
            List<Integer> list = new ArrayList<>();
            fun(list,graph.dis, sc.nextInt(),k,new boolean[n+1],-1);
            list.sort(Comparator.comparingInt(o -> o));
            System.out.println(list);
        }
    }
    public static void fun(List<Integer> list,int[][] dis, int t,int k,boolean[] visited,int from){
        if (visited[t]) return;
        if(from==-1||dis[t][from]/k>0){
            list.add(t);
        }
        visited[t]=true;
        //走下一个最短且未走过的点
        int max=Integer.MIN_VALUE;
        int next=-1;
        for (int i = 1; i < dis.length; i++) {
            //到下一个点的距离小于最小值，且未走过，且到下一个点的距离+当前距离大于最小值
            if (dis[t][i]!=0&&dis[t][i]>max&&!visited[i]){
                max=dis[t][i];
                next=i;
            }
        }
        if (next==-1) return;   //没有下一个点
        fun(list,dis,next,k,visited,t);
    }

    static class Graph {
        int[][] dis;

        public Graph(int size) {
            dis = new int[size + 1][size + 1];
        }

        public void insert(String[] edges) {
            int pre = Integer.parseInt(edges[0]);
            for (int i = 2; i < edges.length; i += 2) {
                int cur = Integer.parseInt(edges[i]);
                dis[pre][cur] = Integer.parseInt(edges[i - 1]);
                dis[cur][pre] = Integer.parseInt(edges[i - 1]);
                pre = cur;
            }
        }

        public void builder() {
            for (int k = 1; k < dis.length; k++) {
                for (int i = 1; i < dis.length; i++) {
                    for (int j = 1; j < dis.length; j++) {
                        if (i == j) continue;
                        if (dis[i][j]==0){
                            dis[i][j]=dis[i][k]+dis[k][j];
                            continue;
                        }
                        if (dis[i][k]==0||dis[k][j]==0) {   //有一个为0，说明不连通
                            continue;
                        }
                        if (dis[i][k] + dis[k][j] < dis[i][j]) { //到每个点的最短距离
                            dis[i][j] = dis[i][k] + dis[k][j];
                        }
                    }
                }
            }
        }
    }
}
